package day12;

import java.util.Scanner;

public class Hmoework {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        System.out.print("请输入年龄：");
        int age=sc.nextInt();
        if (age>0&&age<=100){
            System.out.println("输入了正确的年龄！");
        }else {
            try {
                throw new MyException2("输入错误，年龄为0~100岁！");
            }catch (MyException2 e){
                System.err.println(e.getMessage());
            }
        }
        MyService ms=new MyService();
        try {
            ms.check();
        } catch (MyException1 e) {
            // 处理自定义检查性异常
            System.err.println("程序: " + e.getMessage());
        }
    }

}

class MyService {
    public void check() throws MyException1 {
        boolean err = false;
        if (err) {
            throw new MyException1("出现了错误！");
        }
        System.out.println("成功运行！");
    }
}


class MyException1 extends Exception{
    public MyException1() {

    }
    public MyException1(String msg){
        super(msg);
    }
}

class MyException2 extends Exception{
    public MyException2() {

    }

    public MyException2(String msg){
        super(msg);
    }
}